import { Form, Modal, Steps } from 'antd';
import { FormModalContext } from './FormModalContext';
import { useFormModal } from './utils';
import useFormItems from './useFormItems';
import ModalContainer from './ModalContainer';
import type { AnyObject, StepFormModalProps } from '../type';
import { useState } from 'react';

const StepFormModal = <T extends object = AnyObject>(props: StepFormModalProps<T>) => {
	const {
		modal,
		form: formInstance,
		modalProps,
		closeWarnProps,
		fullscreen,
		draggable = true
	} = props;
	const [modalRef] = useFormModal(modal);

	// 生成Form组件内容
	// const formContent = useFormItems(props);
	// close拦截提示窗
	const [closeModal, closeModalContext] = Modal.useModal();
	// 是否全屏
	const [full, setFull] = useState(fullscreen);
	// form组件实例
	const form = formInstance || Form.useForm<T>()[0];

	return (
		<FormModalContext.Provider value={modalRef}>
			<ModalContainer
				form={form}
				modalProps={modalProps}
				closeWarnProps={closeWarnProps}
				fullscreen={fullscreen}
				closeModal={closeModal}
				draggable={draggable}
				full={full}
				setFull={setFull}
			>
				StepFormModal
				{closeModalContext}
			</ModalContainer>
		</FormModalContext.Provider>
	);
};

export default StepFormModal;
